package com.chain.qs.modules.sys.web;


import com.chain.qs.common.web.BaseController;
import com.chain.qs.modules.biz.service.BasicInfoService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 提供基础信息Controller
 */
@Controller
@RequestMapping(value = "${adminPath}/biz/basic")
public class BasicInfoController extends BaseController {

    @Resource
    private BasicInfoService basicInfoService;

    /**
     * 向设备发送指令
     * @param request
     * @param stationCode
     * @param groupId
     * @param device
     * @param cmd
     * @param value
     * @return
     */
    @ResponseBody
    @RequestMapping("/sendcmd")
    public String sendCMD(HttpServletRequest request, String stationCode ,String groupId ,String device, String cmd ,String value) {
        return basicInfoService.sendCMD(request,stationCode,groupId,device,cmd,value);
    }

    @RequestMapping(value = "getExistWarningMap")
    public String getExistWarningMap(HttpServletResponse response) {
        return renderString(response, basicInfoService.getExistWarningMap());
    }

    @RequestMapping(value = "getExistWarningMapByStationCode")
    public String getExistWarningMapByStationCode(HttpServletResponse response,String stationCode) {
        Map<String, Map<String, List<Map<String, String>>>> warningMaps  = basicInfoService.getExistWarningMap();
        Map<String,Object> warningMap = new HashedMap();
        if(warningMaps.containsKey(stationCode)){
            warningMap.put(stationCode,warningMaps.get(stationCode));
        }
        return renderString(response, warningMap);
    }
}